<?php
namespace Hdphp\Libs;
class SmartyView{
    private static $smarty;
    public function __construct(){
        if(!is_null(self::$smarty)) return;
        //实例化Smarty
        $smarty = new \Smarty();
        //模板目录【App/Home/View/view】【App/Admin/View/Arc】
        $smarty->template_dir = "App/".MODULE."/View/".CONTROLLER;
        //编译目录【Storage/Home/compile/view】
        $path = "Storage/".MODULE."/compile/".CONTROLLER;
        is_dir($path) || mkdir($path,0777,true);
        $smarty->compile_dir = $path;
        //缓存目录【Storage/Home/cache/view】
        $path = "Storage/".MODULE."/cache/" . CONTROLLER;
        is_dir($path)||mkdir($path,0777,true);
        $smarty->cache_dir=$path;
        //是否开启缓存
        $smarty->caching = C("CACHING");
        $smarty->cache_lifetime = C("CACHE_LIFETIME");
        //左定界符
        $smarty->left_delimiter = C("LEFT_DELIMITER");
        //右定界符
        $smarty->right_delimiter = C("RIGHT_DELIMITER");
        self::$smarty = $smarty;
    }
    /**
     * 显示模板
     */
    protected function display($tpl=null){
        $tpl = is_null($tpl) ? ACTION . ".html" : $tpl;
        self::$smarty->display($tpl);
    }
    /**
     * 分配变量
     */
    protected function assign($var,$value){
        self::$smarty->assign($var,$value);
    }
}